package com.zoo.diannaopeijian.service.impl;

import com.zoo.diannaopeijian.common.page.Page;
import com.zoo.diannaopeijian.common.util.CheckUtil;
import com.zoo.diannaopeijian.domain.ShipmentTarget;
import com.zoo.diannaopeijian.mapper.ShipmentTargetMapper;
import com.zoo.diannaopeijian.service.ShipmentTargetService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 出货对象服务实现类
 */
@Service
public class ShipmentTargetServiceImpl implements ShipmentTargetService {
    @Resource
    private ShipmentTargetMapper shipmentTargetMapper;

    @Override
    public boolean addShipmentTarget(ShipmentTarget shipmentTarget) {
        if (CheckUtil.allNullBeanCheck(shipmentTarget)) {
            return true;
        }
        return shipmentTargetMapper.insertSelective(shipmentTarget) == 1;
    }

    @Override
    public boolean deleteShipmentTargetById(Integer shipmentTargetId) {
        if (shipmentTargetId == null) {
            throw new NullPointerException();
        }
        return shipmentTargetMapper.deleteByPrimaryKey(shipmentTargetId) == 1;
    }

    @Override
    public boolean updateShipmentTarget(ShipmentTarget shipmentTarget) {
        if (CheckUtil.allNullBeanCheck(shipmentTarget)) {
            return true;
        }
        return shipmentTargetMapper.updateByPrimaryKeySelective(shipmentTarget) == 1;
    }

    @Override
    public List<ShipmentTarget> getAllShipmentTarget(Page page) {
        if (page != null) {
            page.onPage();
        }
        return shipmentTargetMapper.select(null);
    }
}
